#!/usr/bin/env python

import imp
import os
import subprocess

python_dir  = 'python'
kt_dir      = os.path.join(python_dir, 'kt')
config_file = os.path.join(kt_dir, 'config.py')
config      = imp.load_source('config', config_file)

link_command = [
    'gcc',
    '-shared',
    '-o',
    os.path.join(config.kt_packages_dir, 'fontforge.so'),
    '-Wl,--whole-archive',
    'libfontforge.a',
    'libgioftp.a',
    'libgunicode.a',
    'libgutils.a',
    '-Wl,--no-whole-archive',
    ]
p = subprocess.Popen(link_command, cwd = os.path.join('fontforge', '.libs'))
os.waitpid(p.pid, 0)[1]

try:
    os.remove(os.path.join(config.kt_packages_dir, 'psMat.so'))
except OSError:
    pass

os.symlink('fontforge.so', os.path.join(config.kt_packages_dir, 'psMat.so'))
